package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.MonthlyImageDetail;
import com.ruoyi.project.service.IMonthlyImageDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月度形象图详情Controller
 * 
 * @author liboyu
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/project/monthImageDetail")
public class MonthlyImageDetailController extends BaseController
{
    @Autowired
    private IMonthlyImageDetailService monthlyImageDetailService;

    /**
     * 查询月度形象图详情列表
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:list')")
    @GetMapping("/list")
    public TableDataInfo list(MonthlyImageDetail monthlyImageDetail)
    {
        startPage();
        List<MonthlyImageDetail> list = monthlyImageDetailService.selectMonthlyImageDetailList(monthlyImageDetail);
        return getDataTable(list);
    }

    /**
     * 导出月度形象图详情列表
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:export')")
    @Log(title = "月度形象图详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MonthlyImageDetail monthlyImageDetail)
    {
        List<MonthlyImageDetail> list = monthlyImageDetailService.selectMonthlyImageDetailList(monthlyImageDetail);
        ExcelUtil<MonthlyImageDetail> util = new ExcelUtil<MonthlyImageDetail>(MonthlyImageDetail.class);
        util.exportExcel(response, list, "月度形象图详情数据");
    }

    /**
     * 获取月度形象图详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:query')")
    @GetMapping(value = "/{imageDetailId}")
    public AjaxResult getInfo(@PathVariable("imageDetailId") Long imageDetailId)
    {
        return success(monthlyImageDetailService.selectMonthlyImageDetailByImageDetailId(imageDetailId));
    }

    /**
     * 新增月度形象图详情
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:add')")
    @Log(title = "月度形象图详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody MonthlyImageDetail monthlyImageDetail)
    {
        //唯一验证
        Long id =monthlyImageDetailService.checkNameUnique(monthlyImageDetail);
        if (id != null){
            return error("所选择的月份已经上传,不能添加");
        }
        return toAjax(monthlyImageDetailService.insertMonthlyImageDetail(monthlyImageDetail));
    }

    /**
     * 修改月度形象图详情
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:edit')")
    @Log(title = "月度形象图详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody MonthlyImageDetail monthlyImageDetail)
    {
        //唯一验证
        Long id =monthlyImageDetailService.checkNameUnique(monthlyImageDetail);
        if (id != null){
            return error("所选择的月份已经上传,不能修改");
        }
        return toAjax(monthlyImageDetailService.updateMonthlyImageDetail(monthlyImageDetail));
    }

    /**
     * 删除月度形象图详情
     */
    @PreAuthorize("@ss.hasPermi('project:monthImage:remove')")
    @Log(title = "月度形象图详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageDetailIds}")
    public AjaxResult remove(@PathVariable Long[] imageDetailIds)
    {
        return toAjax(monthlyImageDetailService.deleteMonthlyImageDetailByImageDetailIds(imageDetailIds));
    }
}
